{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 案例篇：销售数据统计分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据文件说明\n",
    "数据文件为 2018年销售汇总表.csv，文件共有 5 列，分别为账号（字符串）、姓名（字符串）、单品（字符串）、数量（整数）、单价（2 位小数）、金额（2 位小数）、日期（DateTime）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 导入相关包\n",
    "运行之前确保自己已安装了这些包\n",
    "```python\n",
    "pip install pandas numpy sparklines\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np \n",
    "import pandas as pd \n",
    "from sparklines  import sparklines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据文件读取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('data/2018年销售汇总表.csv',parse_dates = ['日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>账号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>单品</th>\n",
       "      <th>数量</th>\n",
       "      <th>单价</th>\n",
       "      <th>金额</th>\n",
       "      <th>日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>740150</td>\n",
       "      <td>Barton LLC</td>\n",
       "      <td>B1-20000</td>\n",
       "      <td>39</td>\n",
       "      <td>86.69</td>\n",
       "      <td>3380.91</td>\n",
       "      <td>2018-01-01 07:21:51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>714466</td>\n",
       "      <td>Trantow-Barrows</td>\n",
       "      <td>S2-77896</td>\n",
       "      <td>-1</td>\n",
       "      <td>63.16</td>\n",
       "      <td>-63.16</td>\n",
       "      <td>2018-01-01 10:00:47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>218895</td>\n",
       "      <td>Kulas Inc</td>\n",
       "      <td>B1-69924</td>\n",
       "      <td>23</td>\n",
       "      <td>90.70</td>\n",
       "      <td>2086.10</td>\n",
       "      <td>2018-01-01 13:24:58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>307599</td>\n",
       "      <td>Kassulke, Ondricka and Metz</td>\n",
       "      <td>S1-65481</td>\n",
       "      <td>41</td>\n",
       "      <td>21.05</td>\n",
       "      <td>863.05</td>\n",
       "      <td>2018-01-01 15:05:22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>412290</td>\n",
       "      <td>Jerde-Hilpert</td>\n",
       "      <td>S2-34077</td>\n",
       "      <td>6</td>\n",
       "      <td>83.21</td>\n",
       "      <td>499.26</td>\n",
       "      <td>2018-01-01 23:26:55</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       账号                           姓名        单品  数量     单价       金额  \\\n",
       "0  740150                   Barton LLC  B1-20000  39  86.69  3380.91   \n",
       "1  714466              Trantow-Barrows  S2-77896  -1  63.16   -63.16   \n",
       "2  218895                    Kulas Inc  B1-69924  23  90.70  2086.10   \n",
       "3  307599  Kassulke, Ondricka and Metz  S1-65481  41  21.05   863.05   \n",
       "4  412290                Jerde-Hilpert  S2-34077   6  83.21   499.26   \n",
       "\n",
       "                   日期  \n",
       "0 2018-01-01 07:21:51  \n",
       "1 2018-01-01 10:00:47  \n",
       "2 2018-01-01 13:24:58  \n",
       "3 2018-01-01 15:05:22  \n",
       "4 2018-01-01 23:26:55  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1500 entries, 0 to 1499\n",
      "Data columns (total 7 columns):\n",
      " #   Column  Non-Null Count  Dtype         \n",
      "---  ------  --------------  -----         \n",
      " 0   账号      1500 non-null   int64         \n",
      " 1   姓名      1500 non-null   object        \n",
      " 2   单品      1500 non-null   object        \n",
      " 3   数量      1500 non-null   int64         \n",
      " 4   单价      1500 non-null   float64       \n",
      " 5   金额      1500 non-null   float64       \n",
      " 6   日期      1500 non-null   datetime64[ns]\n",
      "dtypes: datetime64[ns](1), float64(2), int64(2), object(2)\n",
      "memory usage: 82.2+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按客人姓名查看消费金额的平均值与总金额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean</th>\n",
       "      <th>sum</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>姓名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Barton LLC</th>\n",
       "      <td>1334.615854</td>\n",
       "      <td>109438.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cronin, Oberbrunner and Spencer</th>\n",
       "      <td>1339.321642</td>\n",
       "      <td>89734.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Frami, Hills and Schmidt</th>\n",
       "      <td>1438.466528</td>\n",
       "      <td>103569.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fritsch, Russel and Anderson</th>\n",
       "      <td>1385.366790</td>\n",
       "      <td>112214.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Halvorson, Crona and Champlin</th>\n",
       "      <td>1206.971724</td>\n",
       "      <td>70004.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Herman LLC</th>\n",
       "      <td>1336.532258</td>\n",
       "      <td>82865.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jerde-Hilpert</th>\n",
       "      <td>1265.072247</td>\n",
       "      <td>112591.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kassulke, Ondricka and Metz</th>\n",
       "      <td>1350.797969</td>\n",
       "      <td>86451.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keeling LLC</th>\n",
       "      <td>1363.977027</td>\n",
       "      <td>100934.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kiehn-Spinka</th>\n",
       "      <td>1260.870506</td>\n",
       "      <td>99608.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Koepp Ltd</th>\n",
       "      <td>1264.152927</td>\n",
       "      <td>103660.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kuhn-Gusikowski</th>\n",
       "      <td>1247.866849</td>\n",
       "      <td>91094.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kulas Inc</th>\n",
       "      <td>1461.191064</td>\n",
       "      <td>137351.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pollich LLC</th>\n",
       "      <td>1196.536712</td>\n",
       "      <td>87347.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Purdy-Kunde</th>\n",
       "      <td>1469.777547</td>\n",
       "      <td>77898.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sanford and Sons</th>\n",
       "      <td>1391.872958</td>\n",
       "      <td>98822.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stokes LLC</th>\n",
       "      <td>1271.332222</td>\n",
       "      <td>91535.92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Trantow-Barrows</th>\n",
       "      <td>1312.567872</td>\n",
       "      <td>123381.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>White-Trantow</th>\n",
       "      <td>1579.558023</td>\n",
       "      <td>135841.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Will LLC</th>\n",
       "      <td>1411.318919</td>\n",
       "      <td>104437.60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        mean        sum\n",
       "姓名                                                     \n",
       "Barton LLC                       1334.615854  109438.50\n",
       "Cronin, Oberbrunner and Spencer  1339.321642   89734.55\n",
       "Frami, Hills and Schmidt         1438.466528  103569.59\n",
       "Fritsch, Russel and Anderson     1385.366790  112214.71\n",
       "Halvorson, Crona and Champlin    1206.971724   70004.36\n",
       "Herman LLC                       1336.532258   82865.00\n",
       "Jerde-Hilpert                    1265.072247  112591.43\n",
       "Kassulke, Ondricka and Metz      1350.797969   86451.07\n",
       "Keeling LLC                      1363.977027  100934.30\n",
       "Kiehn-Spinka                     1260.870506   99608.77\n",
       "Koepp Ltd                        1264.152927  103660.54\n",
       "Kuhn-Gusikowski                  1247.866849   91094.28\n",
       "Kulas Inc                        1461.191064  137351.96\n",
       "Pollich LLC                      1196.536712   87347.18\n",
       "Purdy-Kunde                      1469.777547   77898.21\n",
       "Sanford and Sons                 1391.872958   98822.98\n",
       "Stokes LLC                       1271.332222   91535.92\n",
       "Trantow-Barrows                  1312.567872  123381.38\n",
       "White-Trantow                    1579.558023  135841.99\n",
       "Will LLC                         1411.318919  104437.60"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('姓名')['金额'].agg(['mean','sum'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用 $ 符号格式化字符串，包括2位小数点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style><table id=\"T_8926b_\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >mean</th>        <th class=\"col_heading level0 col1\" >sum</th>    </tr>    <tr>        <th class=\"index_name level0\" >姓名</th>        <th class=\"blank\" ></th>        <th class=\"blank\" ></th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                        <th id=\"T_8926b_level0_row0\" class=\"row_heading level0 row0\" >Barton LLC</th>\n",
       "                        <td id=\"T_8926b_row0_col0\" class=\"data row0 col0\" >$1,334.62</td>\n",
       "                        <td id=\"T_8926b_row0_col1\" class=\"data row0 col1\" >$109,438.50</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row1\" class=\"row_heading level0 row1\" >Cronin, Oberbrunner and Spencer</th>\n",
       "                        <td id=\"T_8926b_row1_col0\" class=\"data row1 col0\" >$1,339.32</td>\n",
       "                        <td id=\"T_8926b_row1_col1\" class=\"data row1 col1\" >$89,734.55</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row2\" class=\"row_heading level0 row2\" >Frami, Hills and Schmidt</th>\n",
       "                        <td id=\"T_8926b_row2_col0\" class=\"data row2 col0\" >$1,438.47</td>\n",
       "                        <td id=\"T_8926b_row2_col1\" class=\"data row2 col1\" >$103,569.59</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row3\" class=\"row_heading level0 row3\" >Fritsch, Russel and Anderson</th>\n",
       "                        <td id=\"T_8926b_row3_col0\" class=\"data row3 col0\" >$1,385.37</td>\n",
       "                        <td id=\"T_8926b_row3_col1\" class=\"data row3 col1\" >$112,214.71</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row4\" class=\"row_heading level0 row4\" >Halvorson, Crona and Champlin</th>\n",
       "                        <td id=\"T_8926b_row4_col0\" class=\"data row4 col0\" >$1,206.97</td>\n",
       "                        <td id=\"T_8926b_row4_col1\" class=\"data row4 col1\" >$70,004.36</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row5\" class=\"row_heading level0 row5\" >Herman LLC</th>\n",
       "                        <td id=\"T_8926b_row5_col0\" class=\"data row5 col0\" >$1,336.53</td>\n",
       "                        <td id=\"T_8926b_row5_col1\" class=\"data row5 col1\" >$82,865.00</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row6\" class=\"row_heading level0 row6\" >Jerde-Hilpert</th>\n",
       "                        <td id=\"T_8926b_row6_col0\" class=\"data row6 col0\" >$1,265.07</td>\n",
       "                        <td id=\"T_8926b_row6_col1\" class=\"data row6 col1\" >$112,591.43</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row7\" class=\"row_heading level0 row7\" >Kassulke, Ondricka and Metz</th>\n",
       "                        <td id=\"T_8926b_row7_col0\" class=\"data row7 col0\" >$1,350.80</td>\n",
       "                        <td id=\"T_8926b_row7_col1\" class=\"data row7 col1\" >$86,451.07</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row8\" class=\"row_heading level0 row8\" >Keeling LLC</th>\n",
       "                        <td id=\"T_8926b_row8_col0\" class=\"data row8 col0\" >$1,363.98</td>\n",
       "                        <td id=\"T_8926b_row8_col1\" class=\"data row8 col1\" >$100,934.30</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row9\" class=\"row_heading level0 row9\" >Kiehn-Spinka</th>\n",
       "                        <td id=\"T_8926b_row9_col0\" class=\"data row9 col0\" >$1,260.87</td>\n",
       "                        <td id=\"T_8926b_row9_col1\" class=\"data row9 col1\" >$99,608.77</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row10\" class=\"row_heading level0 row10\" >Koepp Ltd</th>\n",
       "                        <td id=\"T_8926b_row10_col0\" class=\"data row10 col0\" >$1,264.15</td>\n",
       "                        <td id=\"T_8926b_row10_col1\" class=\"data row10 col1\" >$103,660.54</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row11\" class=\"row_heading level0 row11\" >Kuhn-Gusikowski</th>\n",
       "                        <td id=\"T_8926b_row11_col0\" class=\"data row11 col0\" >$1,247.87</td>\n",
       "                        <td id=\"T_8926b_row11_col1\" class=\"data row11 col1\" >$91,094.28</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row12\" class=\"row_heading level0 row12\" >Kulas Inc</th>\n",
       "                        <td id=\"T_8926b_row12_col0\" class=\"data row12 col0\" >$1,461.19</td>\n",
       "                        <td id=\"T_8926b_row12_col1\" class=\"data row12 col1\" >$137,351.96</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row13\" class=\"row_heading level0 row13\" >Pollich LLC</th>\n",
       "                        <td id=\"T_8926b_row13_col0\" class=\"data row13 col0\" >$1,196.54</td>\n",
       "                        <td id=\"T_8926b_row13_col1\" class=\"data row13 col1\" >$87,347.18</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row14\" class=\"row_heading level0 row14\" >Purdy-Kunde</th>\n",
       "                        <td id=\"T_8926b_row14_col0\" class=\"data row14 col0\" >$1,469.78</td>\n",
       "                        <td id=\"T_8926b_row14_col1\" class=\"data row14 col1\" >$77,898.21</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row15\" class=\"row_heading level0 row15\" >Sanford and Sons</th>\n",
       "                        <td id=\"T_8926b_row15_col0\" class=\"data row15 col0\" >$1,391.87</td>\n",
       "                        <td id=\"T_8926b_row15_col1\" class=\"data row15 col1\" >$98,822.98</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row16\" class=\"row_heading level0 row16\" >Stokes LLC</th>\n",
       "                        <td id=\"T_8926b_row16_col0\" class=\"data row16 col0\" >$1,271.33</td>\n",
       "                        <td id=\"T_8926b_row16_col1\" class=\"data row16 col1\" >$91,535.92</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row17\" class=\"row_heading level0 row17\" >Trantow-Barrows</th>\n",
       "                        <td id=\"T_8926b_row17_col0\" class=\"data row17 col0\" >$1,312.57</td>\n",
       "                        <td id=\"T_8926b_row17_col1\" class=\"data row17 col1\" >$123,381.38</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row18\" class=\"row_heading level0 row18\" >White-Trantow</th>\n",
       "                        <td id=\"T_8926b_row18_col0\" class=\"data row18 col0\" >$1,579.56</td>\n",
       "                        <td id=\"T_8926b_row18_col1\" class=\"data row18 col1\" >$135,841.99</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_8926b_level0_row19\" class=\"row_heading level0 row19\" >Will LLC</th>\n",
       "                        <td id=\"T_8926b_row19_col0\" class=\"data row19 col0\" >$1,411.32</td>\n",
       "                        <td id=\"T_8926b_row19_col1\" class=\"data row19 col1\" >$104,437.60</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2305c3c2f40>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('姓名')['金额'].agg(['mean', 'sum']).style.format('${0:,.2f}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 金额显示为不带小数点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style><table id=\"T_2a2dc_\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >mean</th>        <th class=\"col_heading level0 col1\" >sum</th>    </tr>    <tr>        <th class=\"index_name level0\" >姓名</th>        <th class=\"blank\" ></th>        <th class=\"blank\" ></th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row0\" class=\"row_heading level0 row0\" >Barton LLC</th>\n",
       "                        <td id=\"T_2a2dc_row0_col0\" class=\"data row0 col0\" >$1,335</td>\n",
       "                        <td id=\"T_2a2dc_row0_col1\" class=\"data row0 col1\" >$109,438</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row1\" class=\"row_heading level0 row1\" >Cronin, Oberbrunner and Spencer</th>\n",
       "                        <td id=\"T_2a2dc_row1_col0\" class=\"data row1 col0\" >$1,339</td>\n",
       "                        <td id=\"T_2a2dc_row1_col1\" class=\"data row1 col1\" >$89,735</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row2\" class=\"row_heading level0 row2\" >Frami, Hills and Schmidt</th>\n",
       "                        <td id=\"T_2a2dc_row2_col0\" class=\"data row2 col0\" >$1,438</td>\n",
       "                        <td id=\"T_2a2dc_row2_col1\" class=\"data row2 col1\" >$103,570</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row3\" class=\"row_heading level0 row3\" >Fritsch, Russel and Anderson</th>\n",
       "                        <td id=\"T_2a2dc_row3_col0\" class=\"data row3 col0\" >$1,385</td>\n",
       "                        <td id=\"T_2a2dc_row3_col1\" class=\"data row3 col1\" >$112,215</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row4\" class=\"row_heading level0 row4\" >Halvorson, Crona and Champlin</th>\n",
       "                        <td id=\"T_2a2dc_row4_col0\" class=\"data row4 col0\" >$1,207</td>\n",
       "                        <td id=\"T_2a2dc_row4_col1\" class=\"data row4 col1\" >$70,004</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row5\" class=\"row_heading level0 row5\" >Herman LLC</th>\n",
       "                        <td id=\"T_2a2dc_row5_col0\" class=\"data row5 col0\" >$1,337</td>\n",
       "                        <td id=\"T_2a2dc_row5_col1\" class=\"data row5 col1\" >$82,865</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row6\" class=\"row_heading level0 row6\" >Jerde-Hilpert</th>\n",
       "                        <td id=\"T_2a2dc_row6_col0\" class=\"data row6 col0\" >$1,265</td>\n",
       "                        <td id=\"T_2a2dc_row6_col1\" class=\"data row6 col1\" >$112,591</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row7\" class=\"row_heading level0 row7\" >Kassulke, Ondricka and Metz</th>\n",
       "                        <td id=\"T_2a2dc_row7_col0\" class=\"data row7 col0\" >$1,351</td>\n",
       "                        <td id=\"T_2a2dc_row7_col1\" class=\"data row7 col1\" >$86,451</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row8\" class=\"row_heading level0 row8\" >Keeling LLC</th>\n",
       "                        <td id=\"T_2a2dc_row8_col0\" class=\"data row8 col0\" >$1,364</td>\n",
       "                        <td id=\"T_2a2dc_row8_col1\" class=\"data row8 col1\" >$100,934</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row9\" class=\"row_heading level0 row9\" >Kiehn-Spinka</th>\n",
       "                        <td id=\"T_2a2dc_row9_col0\" class=\"data row9 col0\" >$1,261</td>\n",
       "                        <td id=\"T_2a2dc_row9_col1\" class=\"data row9 col1\" >$99,609</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row10\" class=\"row_heading level0 row10\" >Koepp Ltd</th>\n",
       "                        <td id=\"T_2a2dc_row10_col0\" class=\"data row10 col0\" >$1,264</td>\n",
       "                        <td id=\"T_2a2dc_row10_col1\" class=\"data row10 col1\" >$103,661</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row11\" class=\"row_heading level0 row11\" >Kuhn-Gusikowski</th>\n",
       "                        <td id=\"T_2a2dc_row11_col0\" class=\"data row11 col0\" >$1,248</td>\n",
       "                        <td id=\"T_2a2dc_row11_col1\" class=\"data row11 col1\" >$91,094</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row12\" class=\"row_heading level0 row12\" >Kulas Inc</th>\n",
       "                        <td id=\"T_2a2dc_row12_col0\" class=\"data row12 col0\" >$1,461</td>\n",
       "                        <td id=\"T_2a2dc_row12_col1\" class=\"data row12 col1\" >$137,352</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row13\" class=\"row_heading level0 row13\" >Pollich LLC</th>\n",
       "                        <td id=\"T_2a2dc_row13_col0\" class=\"data row13 col0\" >$1,197</td>\n",
       "                        <td id=\"T_2a2dc_row13_col1\" class=\"data row13 col1\" >$87,347</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row14\" class=\"row_heading level0 row14\" >Purdy-Kunde</th>\n",
       "                        <td id=\"T_2a2dc_row14_col0\" class=\"data row14 col0\" >$1,470</td>\n",
       "                        <td id=\"T_2a2dc_row14_col1\" class=\"data row14 col1\" >$77,898</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row15\" class=\"row_heading level0 row15\" >Sanford and Sons</th>\n",
       "                        <td id=\"T_2a2dc_row15_col0\" class=\"data row15 col0\" >$1,392</td>\n",
       "                        <td id=\"T_2a2dc_row15_col1\" class=\"data row15 col1\" >$98,823</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row16\" class=\"row_heading level0 row16\" >Stokes LLC</th>\n",
       "                        <td id=\"T_2a2dc_row16_col0\" class=\"data row16 col0\" >$1,271</td>\n",
       "                        <td id=\"T_2a2dc_row16_col1\" class=\"data row16 col1\" >$91,536</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row17\" class=\"row_heading level0 row17\" >Trantow-Barrows</th>\n",
       "                        <td id=\"T_2a2dc_row17_col0\" class=\"data row17 col0\" >$1,313</td>\n",
       "                        <td id=\"T_2a2dc_row17_col1\" class=\"data row17 col1\" >$123,381</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row18\" class=\"row_heading level0 row18\" >White-Trantow</th>\n",
       "                        <td id=\"T_2a2dc_row18_col0\" class=\"data row18 col0\" >$1,580</td>\n",
       "                        <td id=\"T_2a2dc_row18_col1\" class=\"data row18 col1\" >$135,842</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2a2dc_level0_row19\" class=\"row_heading level0 row19\" >Will LLC</th>\n",
       "                        <td id=\"T_2a2dc_row19_col0\" class=\"data row19 col0\" >$1,411</td>\n",
       "                        <td id=\"T_2a2dc_row19_col1\" class=\"data row19 col1\" >$104,438</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2305e333af0>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('姓名')['金额'].agg(['mean', 'sum']).style.format('${0:,.0f}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按月分析销售金额，并显示每月销售额占年度销售总额比例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>sum</th>\n",
       "      <th>月占比</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-31</td>\n",
       "      <td>185361.66</td>\n",
       "      <td>0.091818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-28</td>\n",
       "      <td>146211.62</td>\n",
       "      <td>0.072426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-03-31</td>\n",
       "      <td>203921.38</td>\n",
       "      <td>0.101012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-04-30</td>\n",
       "      <td>174574.11</td>\n",
       "      <td>0.086475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-05-31</td>\n",
       "      <td>165418.55</td>\n",
       "      <td>0.081940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2018-06-30</td>\n",
       "      <td>174089.33</td>\n",
       "      <td>0.086235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2018-07-31</td>\n",
       "      <td>191662.11</td>\n",
       "      <td>0.094939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2018-08-31</td>\n",
       "      <td>153778.59</td>\n",
       "      <td>0.076174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2018-09-30</td>\n",
       "      <td>168443.17</td>\n",
       "      <td>0.083438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2018-10-31</td>\n",
       "      <td>171495.32</td>\n",
       "      <td>0.084950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2018-11-30</td>\n",
       "      <td>119961.22</td>\n",
       "      <td>0.059423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2018-12-31</td>\n",
       "      <td>163867.26</td>\n",
       "      <td>0.081171</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期        sum       月占比\n",
       "0  2018-01-31  185361.66  0.091818\n",
       "1  2018-02-28  146211.62  0.072426\n",
       "2  2018-03-31  203921.38  0.101012\n",
       "3  2018-04-30  174574.11  0.086475\n",
       "4  2018-05-31  165418.55  0.081940\n",
       "5  2018-06-30  174089.33  0.086235\n",
       "6  2018-07-31  191662.11  0.094939\n",
       "7  2018-08-31  153778.59  0.076174\n",
       "8  2018-09-30  168443.17  0.083438\n",
       "9  2018-10-31  171495.32  0.084950\n",
       "10 2018-11-30  119961.22  0.059423\n",
       "11 2018-12-31  163867.26  0.081171"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "monthly_sales = df.groupby([pd.Grouper(key='日期', freq='M')])['金额'].agg(['sum']).reset_index()\n",
    "monthly_sales['月占比'] = monthly_sales['sum']/df['金额'].sum()\n",
    "monthly_sales"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用格式字典控制每列的格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style><table id=\"T_699cf_\" ><thead>    <tr>        <th class=\"col_heading level0 col0\" >日期</th>        <th class=\"col_heading level0 col1\" >sum</th>        <th class=\"col_heading level0 col2\" >月占比</th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                                <td id=\"T_699cf_row0_col0\" class=\"data row0 col0\" >2018-01</td>\n",
       "                        <td id=\"T_699cf_row0_col1\" class=\"data row0 col1\" >$185,362</td>\n",
       "                        <td id=\"T_699cf_row0_col2\" class=\"data row0 col2\" >9.18%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row1_col0\" class=\"data row1 col0\" >2018-02</td>\n",
       "                        <td id=\"T_699cf_row1_col1\" class=\"data row1 col1\" >$146,212</td>\n",
       "                        <td id=\"T_699cf_row1_col2\" class=\"data row1 col2\" >7.24%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row2_col0\" class=\"data row2 col0\" >2018-03</td>\n",
       "                        <td id=\"T_699cf_row2_col1\" class=\"data row2 col1\" >$203,921</td>\n",
       "                        <td id=\"T_699cf_row2_col2\" class=\"data row2 col2\" >10.10%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row3_col0\" class=\"data row3 col0\" >2018-04</td>\n",
       "                        <td id=\"T_699cf_row3_col1\" class=\"data row3 col1\" >$174,574</td>\n",
       "                        <td id=\"T_699cf_row3_col2\" class=\"data row3 col2\" >8.65%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row4_col0\" class=\"data row4 col0\" >2018-05</td>\n",
       "                        <td id=\"T_699cf_row4_col1\" class=\"data row4 col1\" >$165,419</td>\n",
       "                        <td id=\"T_699cf_row4_col2\" class=\"data row4 col2\" >8.19%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row5_col0\" class=\"data row5 col0\" >2018-06</td>\n",
       "                        <td id=\"T_699cf_row5_col1\" class=\"data row5 col1\" >$174,089</td>\n",
       "                        <td id=\"T_699cf_row5_col2\" class=\"data row5 col2\" >8.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row6_col0\" class=\"data row6 col0\" >2018-07</td>\n",
       "                        <td id=\"T_699cf_row6_col1\" class=\"data row6 col1\" >$191,662</td>\n",
       "                        <td id=\"T_699cf_row6_col2\" class=\"data row6 col2\" >9.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row7_col0\" class=\"data row7 col0\" >2018-08</td>\n",
       "                        <td id=\"T_699cf_row7_col1\" class=\"data row7 col1\" >$153,779</td>\n",
       "                        <td id=\"T_699cf_row7_col2\" class=\"data row7 col2\" >7.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row8_col0\" class=\"data row8 col0\" >2018-09</td>\n",
       "                        <td id=\"T_699cf_row8_col1\" class=\"data row8 col1\" >$168,443</td>\n",
       "                        <td id=\"T_699cf_row8_col2\" class=\"data row8 col2\" >8.34%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row9_col0\" class=\"data row9 col0\" >2018-10</td>\n",
       "                        <td id=\"T_699cf_row9_col1\" class=\"data row9 col1\" >$171,495</td>\n",
       "                        <td id=\"T_699cf_row9_col2\" class=\"data row9 col2\" >8.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row10_col0\" class=\"data row10 col0\" >2018-11</td>\n",
       "                        <td id=\"T_699cf_row10_col1\" class=\"data row10 col1\" >$119,961</td>\n",
       "                        <td id=\"T_699cf_row10_col2\" class=\"data row10 col2\" >5.94%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_699cf_row11_col0\" class=\"data row11 col0\" >2018-12</td>\n",
       "                        <td id=\"T_699cf_row11_col1\" class=\"data row11 col1\" >$163,867</td>\n",
       "                        <td id=\"T_699cf_row11_col2\" class=\"data row11 col2\" >8.12%</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2305e472940>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "format_dict = {'sum': '${0:,.0f}', '日期': '{:%Y-%m}', '月占比': '{:.2%}'}\n",
    "monthly_sales.style.format(format_dict).hide_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 条件格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "#T_f112f_row2_col1,#T_f112f_row2_col2{\n",
       "            background-color:  lightgreen;\n",
       "        }#T_f112f_row10_col1,#T_f112f_row10_col2{\n",
       "            background-color:  red;\n",
       "        }</style><table id=\"T_f112f_\" ><thead>    <tr>        <th class=\"col_heading level0 col0\" >日期</th>        <th class=\"col_heading level0 col1\" >sum</th>        <th class=\"col_heading level0 col2\" >月占比</th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                                <td id=\"T_f112f_row0_col0\" class=\"data row0 col0\" >2018-01</td>\n",
       "                        <td id=\"T_f112f_row0_col1\" class=\"data row0 col1\" >$185,362</td>\n",
       "                        <td id=\"T_f112f_row0_col2\" class=\"data row0 col2\" >9.18%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row1_col0\" class=\"data row1 col0\" >2018-02</td>\n",
       "                        <td id=\"T_f112f_row1_col1\" class=\"data row1 col1\" >$146,212</td>\n",
       "                        <td id=\"T_f112f_row1_col2\" class=\"data row1 col2\" >7.24%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row2_col0\" class=\"data row2 col0\" >2018-03</td>\n",
       "                        <td id=\"T_f112f_row2_col1\" class=\"data row2 col1\" >$203,921</td>\n",
       "                        <td id=\"T_f112f_row2_col2\" class=\"data row2 col2\" >10.10%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row3_col0\" class=\"data row3 col0\" >2018-04</td>\n",
       "                        <td id=\"T_f112f_row3_col1\" class=\"data row3 col1\" >$174,574</td>\n",
       "                        <td id=\"T_f112f_row3_col2\" class=\"data row3 col2\" >8.65%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row4_col0\" class=\"data row4 col0\" >2018-05</td>\n",
       "                        <td id=\"T_f112f_row4_col1\" class=\"data row4 col1\" >$165,419</td>\n",
       "                        <td id=\"T_f112f_row4_col2\" class=\"data row4 col2\" >8.19%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row5_col0\" class=\"data row5 col0\" >2018-06</td>\n",
       "                        <td id=\"T_f112f_row5_col1\" class=\"data row5 col1\" >$174,089</td>\n",
       "                        <td id=\"T_f112f_row5_col2\" class=\"data row5 col2\" >8.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row6_col0\" class=\"data row6 col0\" >2018-07</td>\n",
       "                        <td id=\"T_f112f_row6_col1\" class=\"data row6 col1\" >$191,662</td>\n",
       "                        <td id=\"T_f112f_row6_col2\" class=\"data row6 col2\" >9.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row7_col0\" class=\"data row7 col0\" >2018-08</td>\n",
       "                        <td id=\"T_f112f_row7_col1\" class=\"data row7 col1\" >$153,779</td>\n",
       "                        <td id=\"T_f112f_row7_col2\" class=\"data row7 col2\" >7.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row8_col0\" class=\"data row8 col0\" >2018-09</td>\n",
       "                        <td id=\"T_f112f_row8_col1\" class=\"data row8 col1\" >$168,443</td>\n",
       "                        <td id=\"T_f112f_row8_col2\" class=\"data row8 col2\" >8.34%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row9_col0\" class=\"data row9 col0\" >2018-10</td>\n",
       "                        <td id=\"T_f112f_row9_col1\" class=\"data row9 col1\" >$171,495</td>\n",
       "                        <td id=\"T_f112f_row9_col2\" class=\"data row9 col2\" >8.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row10_col0\" class=\"data row10 col0\" >2018-11</td>\n",
       "                        <td id=\"T_f112f_row10_col1\" class=\"data row10 col1\" >$119,961</td>\n",
       "                        <td id=\"T_f112f_row10_col2\" class=\"data row10 col2\" >5.94%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f112f_row11_col0\" class=\"data row11 col0\" >2018-12</td>\n",
       "                        <td id=\"T_f112f_row11_col1\" class=\"data row11 col1\" >$163,867</td>\n",
       "                        <td id=\"T_f112f_row11_col2\" class=\"data row11 col2\" >8.12%</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2305e472910>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(monthly_sales\n",
    "    .style\n",
    "    .format(format_dict)\n",
    "    .hide_index()\n",
    "    .highlight_max(color='lightgreen')\n",
    "    .highlight_min(color='red')\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 渐变色样式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "#T_2b48b_row0_col1{\n",
       "            background-color:  #69b76d;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row1_col1{\n",
       "            background-color:  #c7abd2;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row2_col1{\n",
       "            background-color:  #00441b;\n",
       "            color:  #f1f1f1;\n",
       "        }#T_2b48b_row3_col1{\n",
       "            background-color:  #bfe5b9;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row4_col1{\n",
       "            background-color:  #ebf4e8;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row5_col1{\n",
       "            background-color:  #c1e6bb;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row6_col1{\n",
       "            background-color:  #37904a;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row7_col1{\n",
       "            background-color:  #e8d5e9;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row8_col1{\n",
       "            background-color:  #e0f2db;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row9_col1{\n",
       "            background-color:  #d1edcb;\n",
       "            color:  #000000;\n",
       "        }#T_2b48b_row10_col1{\n",
       "            background-color:  #40004b;\n",
       "            color:  #f1f1f1;\n",
       "        }#T_2b48b_row11_col1{\n",
       "            background-color:  #f1f5ef;\n",
       "            color:  #000000;\n",
       "        }</style><table id=\"T_2b48b_\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >日期</th>        <th class=\"col_heading level0 col1\" >sum</th>        <th class=\"col_heading level0 col2\" >月占比</th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                        <th id=\"T_2b48b_level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
       "                        <td id=\"T_2b48b_row0_col0\" class=\"data row0 col0\" >2018-01</td>\n",
       "                        <td id=\"T_2b48b_row0_col1\" class=\"data row0 col1\" >$185,362</td>\n",
       "                        <td id=\"T_2b48b_row0_col2\" class=\"data row0 col2\" >9.18%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
       "                        <td id=\"T_2b48b_row1_col0\" class=\"data row1 col0\" >2018-02</td>\n",
       "                        <td id=\"T_2b48b_row1_col1\" class=\"data row1 col1\" >$146,212</td>\n",
       "                        <td id=\"T_2b48b_row1_col2\" class=\"data row1 col2\" >7.24%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
       "                        <td id=\"T_2b48b_row2_col0\" class=\"data row2 col0\" >2018-03</td>\n",
       "                        <td id=\"T_2b48b_row2_col1\" class=\"data row2 col1\" >$203,921</td>\n",
       "                        <td id=\"T_2b48b_row2_col2\" class=\"data row2 col2\" >10.10%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
       "                        <td id=\"T_2b48b_row3_col0\" class=\"data row3 col0\" >2018-04</td>\n",
       "                        <td id=\"T_2b48b_row3_col1\" class=\"data row3 col1\" >$174,574</td>\n",
       "                        <td id=\"T_2b48b_row3_col2\" class=\"data row3 col2\" >8.65%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row4\" class=\"row_heading level0 row4\" >4</th>\n",
       "                        <td id=\"T_2b48b_row4_col0\" class=\"data row4 col0\" >2018-05</td>\n",
       "                        <td id=\"T_2b48b_row4_col1\" class=\"data row4 col1\" >$165,419</td>\n",
       "                        <td id=\"T_2b48b_row4_col2\" class=\"data row4 col2\" >8.19%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row5\" class=\"row_heading level0 row5\" >5</th>\n",
       "                        <td id=\"T_2b48b_row5_col0\" class=\"data row5 col0\" >2018-06</td>\n",
       "                        <td id=\"T_2b48b_row5_col1\" class=\"data row5 col1\" >$174,089</td>\n",
       "                        <td id=\"T_2b48b_row5_col2\" class=\"data row5 col2\" >8.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row6\" class=\"row_heading level0 row6\" >6</th>\n",
       "                        <td id=\"T_2b48b_row6_col0\" class=\"data row6 col0\" >2018-07</td>\n",
       "                        <td id=\"T_2b48b_row6_col1\" class=\"data row6 col1\" >$191,662</td>\n",
       "                        <td id=\"T_2b48b_row6_col2\" class=\"data row6 col2\" >9.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row7\" class=\"row_heading level0 row7\" >7</th>\n",
       "                        <td id=\"T_2b48b_row7_col0\" class=\"data row7 col0\" >2018-08</td>\n",
       "                        <td id=\"T_2b48b_row7_col1\" class=\"data row7 col1\" >$153,779</td>\n",
       "                        <td id=\"T_2b48b_row7_col2\" class=\"data row7 col2\" >7.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row8\" class=\"row_heading level0 row8\" >8</th>\n",
       "                        <td id=\"T_2b48b_row8_col0\" class=\"data row8 col0\" >2018-09</td>\n",
       "                        <td id=\"T_2b48b_row8_col1\" class=\"data row8 col1\" >$168,443</td>\n",
       "                        <td id=\"T_2b48b_row8_col2\" class=\"data row8 col2\" >8.34%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row9\" class=\"row_heading level0 row9\" >9</th>\n",
       "                        <td id=\"T_2b48b_row9_col0\" class=\"data row9 col0\" >2018-10</td>\n",
       "                        <td id=\"T_2b48b_row9_col1\" class=\"data row9 col1\" >$171,495</td>\n",
       "                        <td id=\"T_2b48b_row9_col2\" class=\"data row9 col2\" >8.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row10\" class=\"row_heading level0 row10\" >10</th>\n",
       "                        <td id=\"T_2b48b_row10_col0\" class=\"data row10 col0\" >2018-11</td>\n",
       "                        <td id=\"T_2b48b_row10_col1\" class=\"data row10 col1\" >$119,961</td>\n",
       "                        <td id=\"T_2b48b_row10_col2\" class=\"data row10 col2\" >5.94%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_2b48b_level0_row11\" class=\"row_heading level0 row11\" >11</th>\n",
       "                        <td id=\"T_2b48b_row11_col0\" class=\"data row11 col0\" >2018-12</td>\n",
       "                        <td id=\"T_2b48b_row11_col1\" class=\"data row11 col1\" >$163,867</td>\n",
       "                        <td id=\"T_2b48b_row11_col2\" class=\"data row11 col2\" >8.12%</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2305e472f70>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    monthly_sales.style\n",
    "    .format(format_dict)\n",
    "    .background_gradient(subset=['sum'], cmap='PRGn')\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 单元格柱形条"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "#T_f362a_row0_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 95.4%, transparent 95.4%);\n",
       "        }#T_f362a_row0_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 95.4%, transparent 95.4%);\n",
       "        }#T_f362a_row1_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 85.8%, transparent 85.8%);\n",
       "        }#T_f362a_row1_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 85.8%, transparent 85.8%);\n",
       "        }#T_f362a_row2_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 100.0%, transparent 100.0%);\n",
       "        }#T_f362a_row2_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 100.0%, transparent 100.0%);\n",
       "        }#T_f362a_row3_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 92.8%, transparent 92.8%);\n",
       "        }#T_f362a_row3_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 92.8%, transparent 92.8%);\n",
       "        }#T_f362a_row4_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 90.6%, transparent 90.6%);\n",
       "        }#T_f362a_row4_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 90.6%, transparent 90.6%);\n",
       "        }#T_f362a_row5_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 92.7%, transparent 92.7%);\n",
       "        }#T_f362a_row5_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 92.7%, transparent 92.7%);\n",
       "        }#T_f362a_row6_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 97.0%, transparent 97.0%);\n",
       "        }#T_f362a_row6_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 97.0%, transparent 97.0%);\n",
       "        }#T_f362a_row7_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 87.7%, transparent 87.7%);\n",
       "        }#T_f362a_row7_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 87.7%, transparent 87.7%);\n",
       "        }#T_f362a_row8_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 91.3%, transparent 91.3%);\n",
       "        }#T_f362a_row8_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 91.3%, transparent 91.3%);\n",
       "        }#T_f362a_row9_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 92.0%, transparent 92.0%);\n",
       "        }#T_f362a_row9_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 92.0%, transparent 92.0%);\n",
       "        }#T_f362a_row10_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 79.4%, transparent 79.4%);\n",
       "        }#T_f362a_row10_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 79.4%, transparent 79.4%);\n",
       "        }#T_f362a_row11_col1{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, #FFA07A 50.0%, #FFA07A 90.2%, transparent 90.2%);\n",
       "        }#T_f362a_row11_col2{\n",
       "            width:  10em;\n",
       "             height:  80%;\n",
       "            background:  linear-gradient(90deg, transparent 50.0%, lightblue 50.0%, lightblue 90.2%, transparent 90.2%);\n",
       "        }</style><table id=\"T_f362a_\" ><caption>2018年销售一览表</caption><thead>    <tr>        <th class=\"col_heading level0 col0\" >日期</th>        <th class=\"col_heading level0 col1\" >sum</th>        <th class=\"col_heading level0 col2\" >月占比</th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                                <td id=\"T_f362a_row0_col0\" class=\"data row0 col0\" >2018-01</td>\n",
       "                        <td id=\"T_f362a_row0_col1\" class=\"data row0 col1\" >$185,362</td>\n",
       "                        <td id=\"T_f362a_row0_col2\" class=\"data row0 col2\" >9.18%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row1_col0\" class=\"data row1 col0\" >2018-02</td>\n",
       "                        <td id=\"T_f362a_row1_col1\" class=\"data row1 col1\" >$146,212</td>\n",
       "                        <td id=\"T_f362a_row1_col2\" class=\"data row1 col2\" >7.24%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row2_col0\" class=\"data row2 col0\" >2018-03</td>\n",
       "                        <td id=\"T_f362a_row2_col1\" class=\"data row2 col1\" >$203,921</td>\n",
       "                        <td id=\"T_f362a_row2_col2\" class=\"data row2 col2\" >10.10%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row3_col0\" class=\"data row3 col0\" >2018-04</td>\n",
       "                        <td id=\"T_f362a_row3_col1\" class=\"data row3 col1\" >$174,574</td>\n",
       "                        <td id=\"T_f362a_row3_col2\" class=\"data row3 col2\" >8.65%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row4_col0\" class=\"data row4 col0\" >2018-05</td>\n",
       "                        <td id=\"T_f362a_row4_col1\" class=\"data row4 col1\" >$165,419</td>\n",
       "                        <td id=\"T_f362a_row4_col2\" class=\"data row4 col2\" >8.19%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row5_col0\" class=\"data row5 col0\" >2018-06</td>\n",
       "                        <td id=\"T_f362a_row5_col1\" class=\"data row5 col1\" >$174,089</td>\n",
       "                        <td id=\"T_f362a_row5_col2\" class=\"data row5 col2\" >8.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row6_col0\" class=\"data row6 col0\" >2018-07</td>\n",
       "                        <td id=\"T_f362a_row6_col1\" class=\"data row6 col1\" >$191,662</td>\n",
       "                        <td id=\"T_f362a_row6_col2\" class=\"data row6 col2\" >9.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row7_col0\" class=\"data row7 col0\" >2018-08</td>\n",
       "                        <td id=\"T_f362a_row7_col1\" class=\"data row7 col1\" >$153,779</td>\n",
       "                        <td id=\"T_f362a_row7_col2\" class=\"data row7 col2\" >7.62%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row8_col0\" class=\"data row8 col0\" >2018-09</td>\n",
       "                        <td id=\"T_f362a_row8_col1\" class=\"data row8 col1\" >$168,443</td>\n",
       "                        <td id=\"T_f362a_row8_col2\" class=\"data row8 col2\" >8.34%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row9_col0\" class=\"data row9 col0\" >2018-10</td>\n",
       "                        <td id=\"T_f362a_row9_col1\" class=\"data row9 col1\" >$171,495</td>\n",
       "                        <td id=\"T_f362a_row9_col2\" class=\"data row9 col2\" >8.49%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row10_col0\" class=\"data row10 col0\" >2018-11</td>\n",
       "                        <td id=\"T_f362a_row10_col1\" class=\"data row10 col1\" >$119,961</td>\n",
       "                        <td id=\"T_f362a_row10_col2\" class=\"data row10 col2\" >5.94%</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                                <td id=\"T_f362a_row11_col0\" class=\"data row11 col0\" >2018-12</td>\n",
       "                        <td id=\"T_f362a_row11_col1\" class=\"data row11 col1\" >$163,867</td>\n",
       "                        <td id=\"T_f362a_row11_col2\" class=\"data row11 col2\" >8.12%</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2305e4a24f0>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    monthly_sales\n",
    "    .style\n",
    "    .format(format_dict)\n",
    "    .hide_index()\n",
    "    .bar(color='#FFA07A', vmin=100_000, subset=['sum'], align='zero')\n",
    "    .bar(color='lightblue', vmin=0, subset=['月占比'], align='zero')\n",
    "    .set_caption('2018年销售一览表')\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用 Sparkline 实现可视化效果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sparkline_str(x):\n",
    "    bins=np.histogram(x)[0]\n",
    "    sl = ' '.join(sparklines(bins))\n",
    "    return sl\n",
    "\n",
    "sparkline_str.__name__ = \"走势图\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">数量</th>\n",
       "      <th colspan=\"2\" halign=\"left\">金额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>mean</th>\n",
       "      <th>走势图</th>\n",
       "      <th>mean</th>\n",
       "      <th>走势图</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>姓名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Barton LLC</th>\n",
       "      <td>24.890244</td>\n",
       "      <td>▄▄▃▂▃▆▄█▁▄</td>\n",
       "      <td>1334.615854</td>\n",
       "      <td>█▄▃▆▄▄▁▁▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cronin, Oberbrunner and Spencer</th>\n",
       "      <td>24.970149</td>\n",
       "      <td>█▄▁▄▄▇▅▁▄▄</td>\n",
       "      <td>1339.321642</td>\n",
       "      <td>█▅▅▃▃▃▂▂▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Frami, Hills and Schmidt</th>\n",
       "      <td>26.430556</td>\n",
       "      <td>▄▄▁▂▇█▂▂▅▅</td>\n",
       "      <td>1438.466528</td>\n",
       "      <td>█▅▄▇▅▃▄▁▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fritsch, Russel and Anderson</th>\n",
       "      <td>26.074074</td>\n",
       "      <td>▁▄▇▃▂▂█▃▄▄</td>\n",
       "      <td>1385.366790</td>\n",
       "      <td>▇█▃▄▂▂▁▂▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Halvorson, Crona and Champlin</th>\n",
       "      <td>22.137931</td>\n",
       "      <td>▇▆▆▇█▁▄▂▄▃</td>\n",
       "      <td>1206.971724</td>\n",
       "      <td>██▆▅▁▃▂▂▂▂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Herman LLC</th>\n",
       "      <td>24.806452</td>\n",
       "      <td>▄▃▅▁▆▄▂▆▃█</td>\n",
       "      <td>1336.532258</td>\n",
       "      <td>█▅▇▄▅▄▁▃▂▂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jerde-Hilpert</th>\n",
       "      <td>22.460674</td>\n",
       "      <td>▄▄█▁▂▅▃▂▄▃</td>\n",
       "      <td>1265.072247</td>\n",
       "      <td>█▄▅▂▁▂▃▂▂▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kassulke, Ondricka and Metz</th>\n",
       "      <td>25.734375</td>\n",
       "      <td>▂▂▁▁▂▂▁▅▄█</td>\n",
       "      <td>1350.797969</td>\n",
       "      <td>█▆▆▄▄▃▂▁▁▂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keeling LLC</th>\n",
       "      <td>24.405405</td>\n",
       "      <td>▁▄▇▃▅█▃▄▃▆</td>\n",
       "      <td>1363.977027</td>\n",
       "      <td>▅█▆▃▄▂▂▁▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kiehn-Spinka</th>\n",
       "      <td>22.227848</td>\n",
       "      <td>▃▂█▂▃▅▄▁▄▁</td>\n",
       "      <td>1260.870506</td>\n",
       "      <td>█▇▄▃▃▂▁▂▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Koepp Ltd</th>\n",
       "      <td>21.829268</td>\n",
       "      <td>▅▇█▆▄▇▅▁▅▇</td>\n",
       "      <td>1264.152927</td>\n",
       "      <td>█▇▅▂▄▂▂▂▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kuhn-Gusikowski</th>\n",
       "      <td>22.808219</td>\n",
       "      <td>▂▄█▄▃▁█▄▂▄</td>\n",
       "      <td>1247.866849</td>\n",
       "      <td>▆█▄▃▃▃▃▁▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kulas Inc</th>\n",
       "      <td>24.095745</td>\n",
       "      <td>▇▃▇▂▇▁▅▆█▆</td>\n",
       "      <td>1461.191064</td>\n",
       "      <td>█▅█▂▄▄▄▂▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pollich LLC</th>\n",
       "      <td>23.383562</td>\n",
       "      <td>█▂▅▂▃▆▁▂▄▇</td>\n",
       "      <td>1196.536712</td>\n",
       "      <td>█▆▆▃▃▃▂▂▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Purdy-Kunde</th>\n",
       "      <td>27.358491</td>\n",
       "      <td>▄▅█▁▄▇▅█▇█</td>\n",
       "      <td>1469.777547</td>\n",
       "      <td>█▅▄▃▄▃▃▂▁▂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sanford and Sons</th>\n",
       "      <td>24.000000</td>\n",
       "      <td>▂▂▂▆▁█▂▂▁▅</td>\n",
       "      <td>1391.872958</td>\n",
       "      <td>▅▇█▃▃▄▁▃▁▂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stokes LLC</th>\n",
       "      <td>24.527778</td>\n",
       "      <td>▄▄▄▁▃▂▄█▄▄</td>\n",
       "      <td>1271.332222</td>\n",
       "      <td>█▇▆▆▄▂▂▃▁▂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Trantow-Barrows</th>\n",
       "      <td>24.159574</td>\n",
       "      <td>▅▄▅▂▃▃▄▄▁█</td>\n",
       "      <td>1312.567872</td>\n",
       "      <td>█▇▅▆▃▂▂▁▁▁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>White-Trantow</th>\n",
       "      <td>26.255814</td>\n",
       "      <td>▃▂▆▆▃██▁██</td>\n",
       "      <td>1579.558023</td>\n",
       "      <td>▄█▆▅▄▃▄▂▁▃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Will LLC</th>\n",
       "      <td>24.702703</td>\n",
       "      <td>▂█▁▄▄▄▂▅▅▄</td>\n",
       "      <td>1411.318919</td>\n",
       "      <td>▆█▄▅▄▂▁▂▁▂</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        数量                       金额  \\\n",
       "                                      mean         走势图         mean   \n",
       "姓名                                                                    \n",
       "Barton LLC                       24.890244  ▄▄▃▂▃▆▄█▁▄  1334.615854   \n",
       "Cronin, Oberbrunner and Spencer  24.970149  █▄▁▄▄▇▅▁▄▄  1339.321642   \n",
       "Frami, Hills and Schmidt         26.430556  ▄▄▁▂▇█▂▂▅▅  1438.466528   \n",
       "Fritsch, Russel and Anderson     26.074074  ▁▄▇▃▂▂█▃▄▄  1385.366790   \n",
       "Halvorson, Crona and Champlin    22.137931  ▇▆▆▇█▁▄▂▄▃  1206.971724   \n",
       "Herman LLC                       24.806452  ▄▃▅▁▆▄▂▆▃█  1336.532258   \n",
       "Jerde-Hilpert                    22.460674  ▄▄█▁▂▅▃▂▄▃  1265.072247   \n",
       "Kassulke, Ondricka and Metz      25.734375  ▂▂▁▁▂▂▁▅▄█  1350.797969   \n",
       "Keeling LLC                      24.405405  ▁▄▇▃▅█▃▄▃▆  1363.977027   \n",
       "Kiehn-Spinka                     22.227848  ▃▂█▂▃▅▄▁▄▁  1260.870506   \n",
       "Koepp Ltd                        21.829268  ▅▇█▆▄▇▅▁▅▇  1264.152927   \n",
       "Kuhn-Gusikowski                  22.808219  ▂▄█▄▃▁█▄▂▄  1247.866849   \n",
       "Kulas Inc                        24.095745  ▇▃▇▂▇▁▅▆█▆  1461.191064   \n",
       "Pollich LLC                      23.383562  █▂▅▂▃▆▁▂▄▇  1196.536712   \n",
       "Purdy-Kunde                      27.358491  ▄▅█▁▄▇▅█▇█  1469.777547   \n",
       "Sanford and Sons                 24.000000  ▂▂▂▆▁█▂▂▁▅  1391.872958   \n",
       "Stokes LLC                       24.527778  ▄▄▄▁▃▂▄█▄▄  1271.332222   \n",
       "Trantow-Barrows                  24.159574  ▅▄▅▂▃▃▄▄▁█  1312.567872   \n",
       "White-Trantow                    26.255814  ▃▂▆▆▃██▁██  1579.558023   \n",
       "Will LLC                         24.702703  ▂█▁▄▄▄▂▅▅▄  1411.318919   \n",
       "\n",
       "                                             \n",
       "                                        走势图  \n",
       "姓名                                           \n",
       "Barton LLC                       █▄▃▆▄▄▁▁▁▁  \n",
       "Cronin, Oberbrunner and Spencer  █▅▅▃▃▃▂▂▁▁  \n",
       "Frami, Hills and Schmidt         █▅▄▇▅▃▄▁▁▁  \n",
       "Fritsch, Russel and Anderson     ▇█▃▄▂▂▁▂▁▁  \n",
       "Halvorson, Crona and Champlin    ██▆▅▁▃▂▂▂▂  \n",
       "Herman LLC                       █▅▇▄▅▄▁▃▂▂  \n",
       "Jerde-Hilpert                    █▄▅▂▁▂▃▂▂▁  \n",
       "Kassulke, Ondricka and Metz      █▆▆▄▄▃▂▁▁▂  \n",
       "Keeling LLC                      ▅█▆▃▄▂▂▁▁▁  \n",
       "Kiehn-Spinka                     █▇▄▃▃▂▁▂▁▁  \n",
       "Koepp Ltd                        █▇▅▂▄▂▂▂▁▁  \n",
       "Kuhn-Gusikowski                  ▆█▄▃▃▃▃▁▁▁  \n",
       "Kulas Inc                        █▅█▂▄▄▄▂▁▁  \n",
       "Pollich LLC                      █▆▆▃▃▃▂▂▁▁  \n",
       "Purdy-Kunde                      █▅▄▃▄▃▃▂▁▂  \n",
       "Sanford and Sons                 ▅▇█▃▃▄▁▃▁▂  \n",
       "Stokes LLC                       █▇▆▆▄▂▂▃▁▂  \n",
       "Trantow-Barrows                  █▇▅▆▃▂▂▁▁▁  \n",
       "White-Trantow                    ▄█▆▅▄▃▄▂▁▃  \n",
       "Will LLC                         ▆█▄▅▄▂▁▂▁▂  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('姓名')['数量', '金额'].agg(['mean', sparkline_str])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
